  len1 = length(SPMatrix)
  C = pcoh(SPMatrix,'Ex');
  weights = ProcDef.Weights;
  
  hf=figure;
  kk=1;
  set(hf,'Position',[200   300   800   600]);
  rect = get(hf,'Position'); 
  rect(1:2) = [0 0]; 
  mov = avifile('diw_mumbai_rr.avi','fps',0.5,'compression','indeo5')
for i = 1:12,

    t = tf_r(squeeze(SPMatrix(i,:,:,:)));
    [a,rho] = getrho1frq(t,ProcDef.TLFreq1(i));
    rhxy(i,:) = a;
    rhyx(i,:) = rho;
    t1 = tf(squeeze(SPMatrix(i,:,:,:)),ProcDef);
    [a,rho] = getrho1frq(t1,ProcDef.TLFreq1(i));
    rhxy_s(i,:) = a;
    rhyx_s(i,:) = rho;
    subplot('position',[0.075 0.4 0.9 0.55]);
    semilogy(rhyx(i,:),'b');
    hold on;
    semilogy(rhyx_s(i,:),'r')
    semilogy(1:3:len1,ones([1,length(1:3:len1)])*Rhyx(i),'b*');
    semilogy(1:3:len1,ones([1,length(1:3:len1)])*Rhyx_s(i),'r*');
    axis([1 len1 10e1 10e4]);
    xlabel('Stacks');
    ylabel('\rho Ohm-m');
    title(sprintf('File VP301032.RTS, RR site VP201332; Period = %10.5f S',1/ProcDef.TLFreq1(i)));
    legend('Romote Reference','Single Station');
    hold off;
    subplot('position',[0.075 0.07 0.9 0.2]);
    plot(1:len1,squeeze(SPC(i,:,1)),'b',1:len1,squeeze(abs(SPC(i,:,3))),'r');
    ylabel('Normalized Power nT^2/Hz');
    xlabel('Stacks');
    legend('HxHx*','HxHxremote*',4);
    axis([1 len1 -inf inf]);
     pause(1);
    F = getframe(hf,rect); % records the figure in the rectangle defined
    mov = addframe(mov,F);
    hold off;
     end;
 mov = close(mov);
        
% clear mex % clears all open avi files useful when sharing violation problem occurs  


% for i = 1:ProcDef.len,
%     for j = 1:12,
%        data(:,:)=squeeze(SPMatrix(j,i,:,:));
%        SPC(j,i,:) = gespec1(data);
%    end;
% end;
% 

    